home *** CD-ROM | disk | FTP | other *** search
/ Your Web Site Creator / Your Web Site Creator.iso / WebSite / data1.cab / Program_Executable_Files / Classes / MACANVA2.CLA (.txt) < prev    next >
Encoding:
Java Class File  |  1999-01-13  |  4.7 KB  |  232 lines

  1. import java.applet.Applet;
  2. import java.awt.Canvas;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.image.ImageObserver;
  11.  
  12. public class MarqueeCanvas2 extends Canvas implements Runnable {
  13.    int speed = 100;
  14.    String message;
  15.    int currentX;
  16.    int currentY;
  17.    int theIncrementX = -1;
  18.    int theIncrementY;
  19.    Color bkColor;
  20.    Color fontColor;
  21.    Font font;
  22.    boolean north = false;
  23.    boolean east = false;
  24.    boolean south = false;
  25.    boolean west = false;
  26.    Image bkImage;
  27.    Image image;
  28.    int theIncrement;
  29.    Thread theThread;
  30.    Image osImage;
  31.    Graphics osg;
  32.  
  33.    public MarqueeCanvas2(Applet var1, int var2) {
  34.       this.GetParameters(var1, var2);
  35.    }
  36.  
  37.    void GetParameters(Applet var1, int var2) {
  38.       String var3 = var1.getParameter("marqueeMessage" + var2);
  39.       this.message = AppletParam2.GetString(var3, "");
  40.       var3 = var1.getParameter("marqueeSpeed" + var2);
  41.       this.speed = AppletParam2.GetInt(var3, 100);
  42.       var3 = var1.getParameter("marqueeIncrement" + var2);
  43.       this.theIncrement = AppletParam2.GetInt(var3, 1);
  44.       var3 = var1.getParameter("marqueeBkColor" + var2);
  45.       this.bkColor = AppletParam2.GetColor(var3, (Color)null);
  46.       if (this.bkColor != null) {
  47.          ((Component)this).setBackground(this.bkColor);
  48.       }
  49.  
  50.       var3 = var1.getParameter("marqueeFont" + var2);
  51.       this.font = AppletParam2.GetJavaFont(var3);
  52.       var3 = var1.getParameter("marqueeFontColor" + var2);
  53.       this.fontColor = AppletParam2.GetColor(var3, Color.red);
  54.       var3 = var1.getParameter("marqueeBkImage" + var2);
  55.       this.bkImage = var1.getImage(var1.getCodeBase(), var3);
  56.       var3 = var1.getParameter("marqueeImage" + var2);
  57.       this.image = var1.getImage(var1.getCodeBase(), var3);
  58.       var3 = var1.getParameter("marqueeDirection" + var2);
  59.       String var4 = AppletParam2.GetString(var3, "West");
  60.       if (var4 == null) {
  61.          var4 = "West";
  62.       }
  63.  
  64.       this.SetDirection(var4);
  65.    }
  66.  
  67.    public void Start() {
  68.       this.theThread = new Thread(this);
  69.       this.theThread.start();
  70.    }
  71.  
  72.    public void Stop() {
  73.       this.theThread.stop();
  74.       this.theThread = null;
  75.    }
  76.  
  77.    public void SetDirection(String var1) {
  78.       if (var1.compareTo("East") == 0) {
  79.          this.theIncrementX = this.theIncrement;
  80.          this.theIncrementY = 0;
  81.          this.east = true;
  82.       } else if (var1.compareTo("North") == 0) {
  83.          this.theIncrementX = 0;
  84.          this.theIncrementY = -this.theIncrement;
  85.          this.north = true;
  86.       } else if (var1.compareTo("South") == 0) {
  87.          this.theIncrementX = 0;
  88.          this.theIncrementY = this.theIncrement;
  89.          this.south = true;
  90.       } else {
  91.          this.theIncrementX = -this.theIncrement;
  92.          this.theIncrementY = 0;
  93.          this.west = true;
  94.       }
  95.    }
  96.  
  97.    public void update(Graphics var1) {
  98.       if (this.osImage == null) {
  99.          this.osImage = ((Component)this).createImage(((Component)this).size().width, ((Component)this).size().height);
  100.          this.osg = this.osImage.getGraphics();
  101.       }
  102.  
  103.       this.osg.setFont(this.font);
  104.       FontMetrics var2 = this.osg.getFontMetrics();
  105.       int var3 = var2.stringWidth(this.message);
  106.       int var4 = var2.getHeight();
  107.       this.osg.setColor(((Component)this).getBackground());
  108.       this.osg.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  109.       if (this.bkImage != null) {
  110.          int var5 = this.bkImage.getWidth(this);
  111.          int var6 = this.bkImage.getHeight(this);
  112.          int var7 = ((Component)this).size().width / var5;
  113.          int var8 = ((Component)this).size().height / var6;
  114.          ++var7;
  115.          ++var8;
  116.  
  117.          for(int var9 = 0; var9 < var8; ++var9) {
  118.             for(int var10 = 0; var10 < var7; ++var10) {
  119.                this.osg.drawImage(this.bkImage, var10 * var5, var9 * var6, this);
  120.             }
  121.          }
  122.       }
  123.  
  124.       if (this.west) {
  125.          if (this.message.length() > 0) {
  126.             this.currentY = ((Component)this).size().height / 2 + var4 / 4;
  127.             if (this.currentX <= -var3) {
  128.                this.currentX = ((Component)this).size().width;
  129.             }
  130.  
  131.             this.osg.setColor(this.fontColor);
  132.             this.osg.drawString(this.message, this.currentX, this.currentY);
  133.          }
  134.  
  135.          if (this.image != null) {
  136.             this.currentY = ((Component)this).size().height / 2 - this.image.getHeight(this) / 2;
  137.             if (this.currentX <= -this.image.getWidth(this)) {
  138.                this.currentX = ((Component)this).size().width;
  139.             }
  140.  
  141.             this.osg.drawImage(this.image, this.currentX, this.currentY, this);
  142.          }
  143.       } else if (this.east) {
  144.          if (this.message.length() > 0) {
  145.             this.currentY = ((Component)this).size().height / 2 + var4 / 4;
  146.             if (this.currentX >= ((Component)this).size().width) {
  147.                this.currentX = -var3;
  148.             }
  149.  
  150.             this.osg.setColor(this.fontColor);
  151.             this.osg.drawString(this.message, this.currentX, this.currentY);
  152.          }
  153.  
  154.          if (this.image != null) {
  155.             this.currentY = ((Component)this).size().height / 2 - this.image.getHeight(this) / 2;
  156.             if (this.currentX > ((Component)this).size().width) {
  157.                this.currentX = -this.image.getWidth(this);
  158.             }
  159.  
  160.             this.osg.setColor(this.fontColor);
  161.             this.osg.drawImage(this.image, this.currentX, this.currentY, this);
  162.          }
  163.       } else if (this.north) {
  164.          if (this.message.length() > 0) {
  165.             this.currentX = ((Component)this).size().width / 2 - var3 / 2;
  166.             if (this.currentY == 0) {
  167.                this.currentY = ((Component)this).size().height + var4;
  168.             }
  169.  
  170.             this.osg.setColor(this.fontColor);
  171.             this.osg.drawString(this.message, this.currentX, this.currentY);
  172.          }
  173.  
  174.          if (this.image != null) {
  175.             this.currentX = ((Component)this).size().width / 2 - this.image.getWidth(this) / 2;
  176.             if (this.currentY <= -this.image.getHeight(this)) {
  177.                this.currentY = ((Component)this).size().height;
  178.             }
  179.  
  180.             this.osg.drawImage(this.image, this.currentX, this.currentY, this);
  181.          }
  182.       } else if (this.south) {
  183.          if (this.message.length() > 0) {
  184.             this.currentX = ((Component)this).size().width / 2 - var3 / 2;
  185.             if (this.currentY == ((Component)this).size().height + var4) {
  186.                this.currentY = 0;
  187.             }
  188.  
  189.             this.osg.setColor(this.fontColor);
  190.             this.osg.drawString(this.message, this.currentX, this.currentY);
  191.          }
  192.  
  193.          if (this.image != null) {
  194.             this.currentX = ((Component)this).size().width / 2 - this.image.getWidth(this) / 2;
  195.             if (this.currentY > ((Component)this).size().height) {
  196.                this.currentY = -this.image.getHeight(this);
  197.             }
  198.  
  199.             this.osg.drawImage(this.image, this.currentX, this.currentY, this);
  200.          }
  201.       }
  202.  
  203.       this.currentX += this.theIncrementX;
  204.       this.currentY += this.theIncrementY;
  205.       var1.drawImage(this.osImage, 0, 0, (ImageObserver)null);
  206.    }
  207.  
  208.    public Dimension minimumSize() {
  209.       return new Dimension(10, 10);
  210.    }
  211.  
  212.    public Dimension preferredSize() {
  213.       return new Dimension(10, 10);
  214.    }
  215.  
  216.    public synchronized void reshape(int var1, int var2, int var3, int var4) {
  217.       super.reshape(var1, var2, var3, var4);
  218.       this.osImage = null;
  219.       this.osg = null;
  220.    }
  221.  
  222.    public void run() {
  223.       try {
  224.          while(true) {
  225.             ((Component)this).repaint();
  226.             Thread.sleep((long)this.speed);
  227.          }
  228.       } catch (InterruptedException var1) {
  229.       }
  230.    }
  231. }
  232.